package LeetCode;

/**
 * @Author Kechelle
 * @Date 2020/9/16 11:01
 * @Version 1.0
 */
public class Code50 {
    public static double myPow(double x, int n) {
        double res = 1.0;
        if (n<0){
            x = 1/x;
            n = -n;
        }
        for (int i=n;i!=0;i/=2){
            if (i%2!=0)
                res = res * x;
            x = x * x;
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(Code50.myPow(2.0000,-3));
    }
}
